package ebiz.buddhist.texts;

import com.nbpcorp.mobilead.sdk.MobileAdListener;
import com.nbpcorp.mobilead.sdk.MobileAdView;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class JijangViewNew extends Activity implements MobileAdListener{
	
	
	WebView webview;
	//private AdView adView;
	
	private MobileAdView adView = null;

   @Override
   public void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
	// sekisuri tap메뉴로 변경해서 삭제(타이틀 변경시 에러남) requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
      this.setContentView(R.layout.about);
   // sekisuri tap메뉴로 변경해서 삭제(타이틀 변경시 에러남)	  getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.main_titlebar);
      // adView 만들기
      adView = (MobileAdView) findViewById(R.id.adview1);
      adView.setListener(this);
	  adView.start();
	    
	    
      webview = (WebView) findViewById(R.id.webView);
      WebSettings ws = webview.getSettings();

      ws.setJavaScriptEnabled(true);		// 잡스크립트실행여부
      ws.setJavaScriptCanOpenWindowsAutomatically(true);      
      ws.setDomStorageEnabled(true);
      
      Uri u = getIntent().getData();
    //  String testUrl= "file:///android_asset/about.html";
      webview.loadUrl(u.toString());
    /*  
      Button done = (Button) findViewById(R.id.closeButton);
      done.setOnClickListener(new OnClickListener() {
         public void onClick(final View v) {
            finish();
         }
      });*/
   }
   @Override
	 public boolean onKeyDown(int keyCode, KeyEvent event) {
	  if(event.getAction() == KeyEvent.ACTION_DOWN){
	   if(keyCode == KeyEvent.KEYCODE_BACK && !webview.canGoBack()){
		   finish();
		   return true;
	   }
	   if(keyCode == KeyEvent.KEYCODE_BACK && webview.canGoBack())
	   {
		   webview.goBack();
		   return true;
	   }
	  }
	  return false;
	 }
   public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0,1,0,getString(R.string.menu_home));
		return true;
	}
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case 1:	
			finish();
			Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("file:///android_asset/jijang/jijang_main.html"),this, JijangViewNew.class);
			startActivity(i);
			return true;
		}		
		return false;
	}
	@Override
	protected void onDestroy() {
		super.onDestroy();
		
		if (adView != null) {
			adView.destroy();
			adView = null;
		}
		
	}

	public void onReceive(int err) {
		// event for receive ad 
		
	}
   
}
